import collections
class Solution(object):
    def numberOfSubarrays(self, nums, k):
        prefix = collections.defaultdict(int)
        prefix[0] = 1
        now = 0
        ans = 0
        for num in nums:
            now += num % 2
            ans += prefix[now - k]
            prefix[now] += 1
        return ans


